package commons.base.httpserver.example;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/t1")
    public TestModel t1(@RequestParam("name") String name, @RequestParam("age") int age){
    	System.err.println(this);
    	System.err.println("t1:name = " + name);
    	System.err.println("t1:age = " + age);
    	
//    	ModelAndView modelAndView = new ModelAndView(new FastJsonJsonView());
//    	modelAndView.addObject(new TestModel());
//    	throw new RuntimeException("11111111111111");
    	TestModel testModel = new TestModel();
    	testModel.setAge(100);
    	testModel.setName("yyyyyyyyyyyyyyyyy");
    	return testModel;
//    	return modelAndView;
    }
    
    @RequestMapping("/t2")
    public TestModel t2(@RequestBody TestModel testModel, @RequestHeader(value="contentCompress",required=false) String contentCompress){
    	System.err.println("contentCompress = " + contentCompress);
    	System.err.println("t2:name = " + testModel.getName());
    	System.err.println("t2:age = " + testModel.getAge());
    	
    	TestModel testModel2 = new TestModel();
    	testModel2.setAge(100);
    	testModel2.setName("yyyyyyyyyyyyyyyyy");
    	return testModel2;
    }
    
    public static class TestModel{
    	private String name = "zhang";
    	private int age = 10;
    	private Date date = new Date();
    	private List<String> list = new ArrayList<>();
    	
    	public TestModel(){
    		for(int i=0; i<20; i++){
    			list.add("qqqqqqqqqq");
    		}
    	}
    	
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getAge() {
			return age;
		}
		public void setAge(int age) {
			this.age = age;
		}
		public Date getDate() {
			return date;
		}
		public void setDate(Date date) {
			this.date = date;
		}

		public List<String> getList() {
			return list;
		}

		public void setList(List<String> list) {
			this.list = list;
		}
    	
    }
	
}
